package com.zyz.M_File和IO流.File类.练习;

import java.io.File;

/**
 * @author: vick
 * @Date: 2025/4/7
 * @Description:
 * @version: 1.0
 */
public class Test2 {
    public static void main(String[] args) {
        String dirPath = "testDir";
        File file = new File(dirPath);
        checkJpg(file);
    }

    public static boolean checkJpg(File file) {
        if (file.exists() && file.isDirectory()) {
            File[] files = file.listFiles();
            boolean hasJpg = false;
            if (files != null) {
                for (File file1 : files) {
                    if (file1.isFile() && file1.getName().toLowerCase().endsWith(".jpg")) {
                        System.out.println(file1.getName());
                        hasJpg = true;
                    }
                }
            }
            return hasJpg;
        }else {
            System.out.println("指定目录不是一个有效目录");
            return false;
        }
    }
}
